package com.guaju.yueshangLife.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.activity.CancleOrderReasonDialogActivity;
import com.guaju.yueshangLife.activity.CommentGoodsListActivity;
import com.guaju.yueshangLife.activity.DeliveryDetailActivity;
import com.guaju.yueshangLife.activity.RefundRequestActivity;
import com.guaju.yueshangLife.activity.mine.OrderDetailActivity;
import com.guaju.yueshangLife.bean.MeOrder;
import com.guaju.yueshangLife.bean.MineOrder;
import com.guaju.yueshangLife.bean.OrderJudgeUtil;
import com.guaju.yueshangLife.databinding.FooterHomeItemBinding;
import com.guaju.yueshangLife.databinding.ItemCancledBinding;
import com.guaju.yueshangLife.databinding.ItemDoneBinding;
import com.guaju.yueshangLife.databinding.ItemUncommentBinding;
import com.guaju.yueshangLife.databinding.ItemUnpayBinding;
import com.guaju.yueshangLife.databinding.ItemUnreceivedBinding;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.utils.ToastUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class OrderListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public static final String REQUEST_REASON_SELECTED = "cancle_reason";
    public static final String REQUEST_REASON = "reason";
    public static final String ORDER_ID = "orderId";

    public int getRefund_type() {
        return refund_type;
    }

    public void setRefund_type(int refund_type) {
        this.refund_type = refund_type;
    }

    public int refund_type = 0;
    public int selectedReason = -1;
    Context context;
    List<MineOrder.DataBean> list;
    private int status = 1;

    public static final int TYPE_UNPAY = 9901;
    public static final int TYPE_UNRECEIVED = 9902;
    public static final int TYPE_UNCOMMENT = 9903;
    public static final int TYPE_CANCLED = 9904;
    public static final int TYPE_DONE = 9905;
    public static final int TYPE_REFUND = 9906;

    public static final int LOAD_MORE = 0;
    public static final int LOAD_PULL_TO = 1;
    public static final int LOAD_NONE = 2;
    public static final int LOAD_END = 3;
    private static final int TYPE_FOOTER = -2;
    private static final int TYPE_CONTENT = -4;

    private static final int REQUEST_SELECT_REASON = 1800;

    private int type = TYPE_UNPAY;
    Activity activity;
    private final LayoutInflater layoutInflater;
    private View view;
    private MaterialDialog deleteDialog, confirmDialog;

    public OrderListAdapter(Context context, List list) {
        this.context = context;
        this.list = list;
        activity = (Activity) context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {

        //选择类型
        RecyclerView.ViewHolder result = null;
        switch (type) {
            case TYPE_UNPAY:
                ItemUnpayBinding unpayBinding = DataBindingUtil.inflate(layoutInflater, R.layout.item_unpay, null, false);
                result = new UnPayHolder(unpayBinding.getRoot());
                break;
            case TYPE_UNRECEIVED:
                ItemUnreceivedBinding unreceivedBinding = DataBindingUtil.inflate(layoutInflater, R.layout.item_unreceived, null, false);
                result = new UnReceivedHolder(unreceivedBinding.getRoot());
                break;
            case TYPE_UNCOMMENT:
                ItemUncommentBinding uncommentBinding = DataBindingUtil.inflate(layoutInflater, R.layout.item_uncomment, null, false);
                result = new UnCommentHolder(uncommentBinding.getRoot());
                break;
            case TYPE_CANCLED:
                ItemCancledBinding cancledBinding = DataBindingUtil.inflate(layoutInflater, R.layout.item_cancled, null, false);
                result = new CancledHolder(cancledBinding.getRoot());
                break;
            case TYPE_FOOTER:
                FooterHomeItemBinding mBindFooter = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.footer_home_item, null, false);
                result = new FooterViewHolder(mBindFooter.getRoot());
                break;
            case TYPE_DONE:
                ItemDoneBinding doneBinding = DataBindingUtil.inflate(layoutInflater, R.layout.item_done, null, false);
                result = new DoneHolder(doneBinding.getRoot());
            default:
                break;
        }
        return result;
    }

    //绑定
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder == null) {
            return;
        }
        if (holder instanceof FooterViewHolder) {
            FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
            if (footerViewHolder != null) {
                footerViewHolder.bindItem();
            }
        } else if (holder instanceof UnPayHolder) {
            UnPayHolder h = (UnPayHolder) holder;
            if (h != null) {
                h.setContent(list.get(position));
            }
        } else if (holder instanceof UnReceivedHolder) {
            UnReceivedHolder h = (UnReceivedHolder) holder;
            if (h != null) {
                h.setContent(list.get(position));
            }
        } else if (holder instanceof UnCommentHolder) {
            UnCommentHolder h = (UnCommentHolder) holder;
            if (h != null) {
                h.setContent(list.get(position));
            }
        } else if (holder instanceof CancledHolder) {
            CancledHolder h = (CancledHolder) holder;
            if (h != null) {
                h.setContent(list.get(position));
            }
        } else if (holder instanceof DoneHolder) {
            DoneHolder h = (DoneHolder) holder;
            if (h != null) {
                h.setContent(list.get(position));
            }
        }
    }

    //有多少个item？
    @Override
    public int getItemCount() {
        if (list != null && !list.isEmpty()) {
            return 1 + list.size();
        } else {
            return 0;
        }
    }

    //item类型
    @Override
    public int getItemViewType(int position) {
        if (position + 1 == getItemCount()) {
            type = TYPE_FOOTER;
        } else {
            MineOrder.DataBean dataBean = list.get(position);
            if (dataBean != null) {
                int status = dataBean.getStatus_code();
                switch (status) {
                    case 0:
                        type = TYPE_CANCLED;
                        break;
                    case 1:
                        type = TYPE_UNPAY;
                        break;
                    case 2:
                        type = TYPE_UNPAY;
                        break;
                    case 3:
                        type = TYPE_UNPAY;
                        break;
                    case 4:
                        type = TYPE_UNRECEIVED;
                        break;
                    case 5:
                        type = TYPE_UNRECEIVED;
                        break;
                    case 6:
                        type = TYPE_UNCOMMENT;
                        break;
                    case 7:
                        type = TYPE_DONE;
                        break;
                    default:
                        type = TYPE_REFUND;
                        break;
                }

            }
        }
        return type;
    }


    public interface OnItemClickListener {
        void onItemClick(View v, int position);

        void onItemLongClick(View v);
    }

    public OrderListAdapter.OnItemClickListener mOnItemClickListener;//第二步：声明自定义的接口

    //第三步：定义方法并暴露给外面的调用者
    public void setOnItemClickListener(OrderListAdapter.OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    class UnPayHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ItemUnpayBinding unpayBinding;
        int orderId;

        public UnPayHolder(View itemView) {
            super(itemView);
            unpayBinding = DataBindingUtil.getBinding(itemView);
            itemView.setOnClickListener(this);
            if (1 == refund_type) {
                unpayBinding.tvCancleOrder.setVisibility(View.GONE);
                unpayBinding.tvPay.setVisibility(View.GONE);
                unpayBinding.tvRefund.setVisibility(View.VISIBLE);
            } else {
                unpayBinding.tvCancleOrder.setVisibility(View.VISIBLE);
                unpayBinding.tvPay.setVisibility(View.VISIBLE);
                unpayBinding.tvRefund.setVisibility(View.GONE);
            }


        }

        public void setContent(MineOrder.DataBean bean) {
            orderId = bean.getId();
            unpayBinding.tvOrderNum.setText(bean.getOrder_number() + "");

            int status_code = bean.getStatus_code();
            String status = bean.getStatus();
            unpayBinding.tvOrderStatus.setText(status);
            unpayBinding.tvTotalNumber.setText(bean.getTotal_amount() + "件商品");
            unpayBinding.totalFee.setText(bean.getTotal_account());
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
            unpayBinding.rvInner.setLayoutManager(linearLayoutManager);
            OrderInnerAdapter orderInnerAdapter = new OrderInnerAdapter(activity, bean.getItems());

            orderInnerAdapter.setOnItemClickListener(new OrderInnerAdapter.OnItemClickListener() {
                @Override
                public void onItemClick() {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }

                @Override
                public void onItemLongClick(View v) {

                }
            });
            unpayBinding.rvInner.setAdapter(orderInnerAdapter);
            unpayBinding.tvRefund.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ToastUtil.show("该订单不能申请退款");
                }
            });
        }

        @Override
        public void onClick(View v) {
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }
            });
            unpayBinding.tvCancleOrder.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showCancleOrderDialog(orderId);
                }
            });
        }
    }

    class UnReceivedHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ItemUnreceivedBinding unreceivedBinding;
        int orderId;

        public UnReceivedHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            unreceivedBinding = DataBindingUtil.getBinding(itemView);
            if (1 == refund_type) {
                unreceivedBinding.tvConfirmReceived.setVisibility(View.GONE);
                unreceivedBinding.tvDelivery.setVisibility(View.GONE);
                unreceivedBinding.tvRefund.setVisibility(View.VISIBLE);
            } else {
                unreceivedBinding.tvConfirmReceived.setVisibility(View.VISIBLE);
                unreceivedBinding.tvDelivery.setVisibility(View.VISIBLE);
                unreceivedBinding.tvRefund.setVisibility(View.GONE);
            }


        }

        public void setContent(MineOrder.DataBean bean) {
            orderId = bean.getId();
            unreceivedBinding.tvOrderNum.setText(bean.getOrder_number() + "");
            int status_code = bean.getStatus_code();
            String status = bean.getStatus();
            unreceivedBinding.tvOrderStatus.setText(status);
            unreceivedBinding.tvTotalNumber.setText(bean.getTotal_amount() + "件商品");
            unreceivedBinding.totalFee.setText(bean.getTotal_account());
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
            unreceivedBinding.rvInner.setLayoutManager(linearLayoutManager);
            OrderInnerAdapter orderInnerAdapter = new OrderInnerAdapter(activity, bean.getItems());
            unreceivedBinding.rvInner.setAdapter(orderInnerAdapter);
            orderInnerAdapter.setOnItemClickListener(new OrderInnerAdapter.OnItemClickListener() {
                @Override
                public void onItemClick() {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }

                @Override
                public void onItemLongClick(View v) {

                }
            });

            unreceivedBinding.tvDelivery.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });

            unreceivedBinding.tvDelivery.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, DeliveryDetailActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("orderId", orderId);
                    intent.putExtras(bundle);
                    context.startActivity(intent);

                }
            });
            unreceivedBinding.tvConfirmReceived.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showConfirmOrderDialog(orderId);
                }
            });

            unreceivedBinding.tvRefund.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, RefundRequestActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt(RefundRequestActivity.ORDER_ID,orderId);
                }
            });
        }

        @Override
        public void onClick(View v) {
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }
            });

        }
    }

    class UnCommentHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ItemUncommentBinding uncommentBinding;
        int orderId;
        List<MineOrder.DataBean.ItemsBean> goodsList;

        public UnCommentHolder(View itemView) {
            super(itemView);
            uncommentBinding = DataBindingUtil.getBinding(itemView);
            itemView.setOnClickListener(this);

            if (1 == refund_type) {
                uncommentBinding.tvComment.setVisibility(View.GONE);
                uncommentBinding.tvDelivery.setVisibility(View.GONE);
                uncommentBinding.tvDelete.setVisibility(View.GONE);
                uncommentBinding.tvRefund.setVisibility(View.VISIBLE);

            } else {
                uncommentBinding.tvComment.setVisibility(View.VISIBLE);
                uncommentBinding.tvDelivery.setVisibility(View.VISIBLE);
                uncommentBinding.tvDelete.setVisibility(View.VISIBLE);
                uncommentBinding.tvRefund.setVisibility(View.GONE);
            }


        }

        public void setContent(MineOrder.DataBean bean) {
            orderId = bean.getId();
            uncommentBinding.tvOrderNum.setText(bean.getOrder_number() + "");
            goodsList = bean.getItems();
            int status_code = bean.getStatus_code();
            String status = bean.getStatus();
            uncommentBinding.tvOrderStatus.setText(status);
            uncommentBinding.tvTotalNumber.setText(bean.getTotal_amount() + "件商品");
            uncommentBinding.totalFee.setText(bean.getTotal_account());
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
            uncommentBinding.rvInner.setLayoutManager(linearLayoutManager);
            OrderInnerAdapter orderInnerAdapter = new OrderInnerAdapter(activity, bean.getItems());
            uncommentBinding.rvInner.setAdapter(orderInnerAdapter);
            orderInnerAdapter.setOnItemClickListener(new OrderInnerAdapter.OnItemClickListener() {
                @Override
                public void onItemClick() {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }

                @Override
                public void onItemLongClick(View v) {

                }
            });
            uncommentBinding.tvDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showDeleteOrderDialog(orderId);
                }
            });
            uncommentBinding.tvDelivery.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, DeliveryDetailActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("orderId", orderId);
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                }
            });

            boolean isAllCommended = true;
            for (MineOrder.DataBean.ItemsBean bean1 : goodsList) {
                if (bean1.getIs_review() != 1) {
                    isAllCommended = false;
                }
            }
            if (isAllCommended) {
                uncommentBinding.tvComment.setBackgroundResource(R.drawable.shape_add_cart_unable);
                uncommentBinding.tvComment.setTextColor(Color.parseColor("#666666"));
                uncommentBinding.tvComment.setText("已评价");
            } else {
                uncommentBinding.tvComment.setBackgroundResource(R.drawable.shape_add_cart);
                uncommentBinding.tvComment.setTextColor(Color.parseColor("#6500AC"));
                uncommentBinding.tvComment.setText("评价");
            }
            if (!isAllCommended) {
                uncommentBinding.tvComment.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, CommentGoodsListActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putInt("orderId", orderId);
                        intent.putExtras(bundle);
                        context.startActivity(intent);
                    }
                });
            }
        }

        @Override
        public void onClick(View v) {
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }
            });

        }

    }


    class DoneHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ItemDoneBinding uncommentBinding;
        int orderId;
        List<MineOrder.DataBean.ItemsBean> goodsList;

        public DoneHolder(View itemView) {
            super(itemView);
            uncommentBinding = DataBindingUtil.getBinding(itemView);
            itemView.setOnClickListener(this);
            if (1 == refund_type) {
                uncommentBinding.tvDelivery.setVisibility(View.GONE);
                uncommentBinding.tvDelete.setVisibility(View.GONE);
                uncommentBinding.tvRefund.setVisibility(View.VISIBLE);

            } else {
                uncommentBinding.tvDelivery.setVisibility(View.VISIBLE);
                uncommentBinding.tvDelete.setVisibility(View.VISIBLE);
                uncommentBinding.tvRefund.setVisibility(View.GONE);
            }
        }

        public void setContent(MineOrder.DataBean bean) {
            orderId = bean.getId();
            uncommentBinding.tvOrderNum.setText(bean.getOrder_number() + "");
            goodsList = bean.getItems();
            int status_code = bean.getStatus_code();
            String status = bean.getStatus();
            uncommentBinding.tvOrderStatus.setText(status);
            uncommentBinding.tvTotalNumber.setText(bean.getTotal_amount() + "件商品");
            uncommentBinding.totalFee.setText(bean.getTotal_account());
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
            uncommentBinding.rvInner.setLayoutManager(linearLayoutManager);
            OrderInnerAdapter orderInnerAdapter = new OrderInnerAdapter(activity, bean.getItems());
            uncommentBinding.rvInner.setAdapter(orderInnerAdapter);
            orderInnerAdapter.setOnItemClickListener(new OrderInnerAdapter.OnItemClickListener() {
                @Override
                public void onItemClick() {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }

                @Override
                public void onItemLongClick(View v) {

                }
            });
            uncommentBinding.tvDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showDeleteOrderDialog(orderId);
                }
            });
            uncommentBinding.tvDelivery.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, DeliveryDetailActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("orderId", orderId);
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                }
            });

        }

        @Override
        public void onClick(View v) {
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }
            });

        }

    }

    class CancledHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ItemCancledBinding cancledBinding;
        int orderId;

        public CancledHolder(View itemView) {
            super(itemView);
            cancledBinding = DataBindingUtil.getBinding(itemView);
            itemView.setOnClickListener(this);

            if (1 == refund_type) {
                cancledBinding.tvDelete.setVisibility(View.GONE);
                cancledBinding.tvRefund.setVisibility(View.VISIBLE);
            } else {
                cancledBinding.tvDelete.setVisibility(View.VISIBLE);
                cancledBinding.tvRefund.setVisibility(View.GONE);
            }
        }

        public void setContent(MineOrder.DataBean bean) {
            orderId = bean.getId();
            cancledBinding.tvOrderNum.setText(bean.getOrder_number() + "");

            int status_code = bean.getStatus_code();
            String orderStatus =bean.getStatus();

            cancledBinding.tvOrderStatus.setText(orderStatus);
            cancledBinding.tvTotalNumber.setText(bean.getTotal_amount() + "件商品");
            cancledBinding.totalFee.setText(bean.getTotal_account());
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
            cancledBinding.rvInner.setLayoutManager(linearLayoutManager);
            OrderInnerAdapter orderInnerAdapter = new OrderInnerAdapter(activity, bean.getItems());
            orderInnerAdapter.setOnItemClickListener(new OrderInnerAdapter.OnItemClickListener() {
                @Override
                public void onItemClick() {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }

                @Override
                public void onItemLongClick(View v) {

                }
            });

            cancledBinding.tvDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showDeleteOrderDialog(orderId);
                }
            });
            cancledBinding.rvInner.setAdapter(orderInnerAdapter);

            cancledBinding.tvRefund.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ToastUtil.show("该订单不能申请退款");
                }
            });
        }

        @Override
        public void onClick(View v) {
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, OrderDetailActivity.class);
                    intent.putExtra("order_id", orderId);
                    activity.startActivity(intent);
                }
            });


        }

    }


    /**
     * footer view
     */
    private class FooterViewHolder extends RecyclerView.ViewHolder {

        FooterHomeItemBinding mBindFooter;

        FooterViewHolder(View itemView) {
            super(itemView);
            mBindFooter = DataBindingUtil.getBinding(itemView);
            mBindFooter.rlMore.setGravity(Gravity.CENTER);
        }

        private void bindItem() {
            switch (status) {
                case LOAD_MORE:
                    mBindFooter.progress.setVisibility(View.VISIBLE);
                    mBindFooter.tvLoadPrompt.setText("正在加载...");
                    itemView.setVisibility(View.VISIBLE);
                    mBindFooter.tvLoadPrompt.setVisibility(View.VISIBLE);
                    mBindFooter.homeBottom.setVisibility(View.INVISIBLE);
                    break;
                case LOAD_PULL_TO:
                    mBindFooter.progress.setVisibility(View.GONE);
                    mBindFooter.tvLoadPrompt.setText("上拉加载更多");
                    itemView.setVisibility(View.VISIBLE);
                    mBindFooter.tvLoadPrompt.setVisibility(View.VISIBLE);
                    mBindFooter.homeBottom.setVisibility(View.INVISIBLE);
                    break;
                case LOAD_NONE:
                    mBindFooter.progress.setVisibility(View.GONE);
                    mBindFooter.tvLoadPrompt.setText("暂无数据");
                    mBindFooter.tvLoadPrompt.setVisibility(View.VISIBLE);
                    mBindFooter.homeBottom.setVisibility(View.INVISIBLE);
                    break;
                case LOAD_END:
                    mBindFooter.progress.setVisibility(View.GONE);
                    mBindFooter.tvLoadPrompt.setVisibility(View.GONE);
                    mBindFooter.homeBottom.setVisibility(View.GONE);
//                    itemView.setVisibility(View.GONE);
                default:
                    break;
            }
        }

    }

    /**
     * 这里规定 position =  getItemCount() - 1 时
     * 就为尾布局，设置为占满整屏幕宽
     * getItemCount() 改了 ，这里就不用改
     */
    private boolean isFooter(int position) {
        return position < getItemCount() && position >= getItemCount() - 1;
    }

    public void updateLoadStatus(int status) {
        this.status = status;
        notifyDataSetChanged();
    }

    public int getLoadStatus() {
        return this.status;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void showDeleteOrderDialog(final int orderId) {
        deleteDialog = new MaterialDialog.Builder(activity)
                .title("确认删除")
                .content("删除后将不能恢复，确认删除？")
                .negativeText("确认")
                .negativeColor(activity.getResources().getColor(R.color.c_gray1))
                .positiveText("取消")
                .positiveColor(activity.getResources().getColor(R.color.colorPrimary))
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
//                                TODO
                        deleteDialog.dismiss();
                    }
                })
                .onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

                        /**
                         * 删除订单
                         */
                        ApiEntity.deleteOrder(orderId);

                        deleteDialog.dismiss();
                    }
                })
                .build();
        deleteDialog.show();
    }

    public void showConfirmOrderDialog(final int orderId) {
        confirmDialog = new MaterialDialog.Builder(activity)
                .title("确认收货")
                .content("确认收到该订单商品？")
                .negativeText("确认")
                .negativeColor(activity.getResources().getColor(R.color.c_gray1))
                .positiveText("取消")
                .positiveColor(activity.getResources().getColor(R.color.colorPrimary))
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
//                                TODO
                        confirmDialog.dismiss();
                    }
                })
                .onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

                        /**
                         * 确认收货
                         */
                        ApiEntity.receiveOrder(orderId);

                        confirmDialog.dismiss();
                    }
                })
                .build();
        confirmDialog.show();
    }

    public void showCancleOrderDialog(int orderId) {
        Intent intent = new Intent(activity, CancleOrderReasonDialogActivity.class);
        intent.putExtra(REQUEST_REASON_SELECTED, selectedReason);
        intent.putExtra(ORDER_ID, orderId);
        activity.startActivityForResult(intent, REQUEST_SELECT_REASON);
    }


}